package ccnu.agile.controller;

import ccnu.agile.annotations.CApi;
import ccnu.agile.bean.request.FileRequest;
import ccnu.agile.bean.response.Response;
import ccnu.agile.enums.CResource;
import ccnu.agile.enums.FileBusiness;
import ccnu.agile.service.IFileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import sun.security.krb5.internal.PAForUserEnc;

/**
 * @Description: 文件上传控制器类
 * @Author: JreamY
 * @Date: 2021/11/25
 **/
@RestController
@RequestMapping("/file_upload")
public class FileUploadController {

    @Autowired
    private IFileUploadService fileUploadService;

    /**
     * 用户头像上传
     *
     * @param file
     * @param token
     * @return
     */
    @PostMapping("/user_face")
    @CApi(resource = CResource.SPECIAL, special = true, specialRequestLog = "/file_upload/user_face")
    public Response uploadFile(
            @RequestParam("file") MultipartFile file,
            @RequestParam("token") String token
    ) {

        FileRequest request = new FileRequest();
        request.setFile(file);
        request.setToken(token);
        request.setBusiness(FileBusiness.USER_FACE);
        return fileUploadService.uploadFile(request);
    }
}
